/* 
 * Copyright (c) 2006 Israfil Consulting Services Corporation
 * Copyright (c) 2006 Christian Edward Gruber
 * All Rights Reserved
 *
 * $Id: Strings.java 617 2008-04-14 13:46:15Z christianedwardgruber $
 */
package net.israfil.foundation.core;

import java.util.Arrays;

/**
 * A Utility class that provides general string manipulation help.
 * 
 * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber</a>
 * @author Latest: $Author: christianedwardgruber $
 * @version $Revision: 617 $
 */
public class Strings {
	
	public static String camel(String string) {
		if (string == null) return null;
		if (string.length() < 1) return string;
		StringBuffer sb = new StringBuffer(string);
		sb.replace(0,1,sb.substring(0,1).toUpperCase());
		return sb.toString();
	}

	public static String camelAllWords(String string, String separator) {
		StringBuffer sb = new StringBuffer();
		boolean first = true;
		for (String _string : string.split(separator)) {
			if (!first) sb.append(separator);
			else first = false;
			sb.append(camel(_string));
		}
		return sb.toString();
	}
	
	public static String concatenate(String separator, Iterable<String> strings) {
		if (strings == null) return "";
		boolean first = true;
		StringBuffer sb = new StringBuffer();
		for (String string : strings) {
			if (first) {
				first = false;
				sb.append(string);
			} else {
				sb.append(separator).append(string);
			}
		}		
		return sb.toString();
	}
	public static String concatenate(String separator, String ... strings) {
		if (strings == null) return "";
		return concatenate(separator,Arrays.asList(strings));
	}
}
